<template>
  <div>
    <n-button @click="open">连接</n-button>
    {{ status }}
    <n-button @click="close">断开</n-button>
    <n-input v-model:value="messageSend" />
    <n-button @click="sendMsg">发送</n-button>
    {{ data }}
  </div>
</template>

<script lang="tsx" setup>
import { token } from "@/utils";
import { useWebSocket } from "./websocket";

defineOptions({ name: "FeatSocket" });

const messageSend = ref("");

const { status, data, open, close, send } = useWebSocket(token.get()!);

const sendMsg = () => {
  const callback = (status: boolean, data: any) => {
    console.log(status, data);
  };

  send("match", messageSend.value, callback);
};
</script>
